package me.zhengjie.minbearwcs.dao.rework.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import lombok.RequiredArgsConstructor;
import me.zhengjie.minbearwcs.dao.rework.inf.ReworkOrderDetailDao;
import me.zhengjie.minbearwcs.entity.Mapper.rework.ReworkOrderDetailMapper;
import me.zhengjie.minbearwcs.entity.PO.wcs.rework.ReworkOrderDetail;
import me.zhengjie.minbearwcs.entity.PO.wcs.rework.status.ReworkOrderDetailStatus;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@RequiredArgsConstructor
public class ReworkOrderDetailDaoImpl implements ReworkOrderDetailDao {

    private final ReworkOrderDetailMapper mapper;

    @Override
    public boolean insert(ReworkOrderDetail reworkOrderDetail) {
        return mapper.insert(reworkOrderDetail) == 1;
    }



    @Override
    public boolean updateStatusByDetailId(String detailId, ReworkOrderDetailStatus status) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(ReworkOrderDetail::getReworkOrderDetailCode,detailId)
                .set(ReworkOrderDetail::getStatus,status)
                .update();
    }

    @Override
    public Long selectExcludeStatusCountByReworkOrderCode(String reworkOrderCode, ReworkOrderDetailStatus status) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(ReworkOrderDetail::getReworkOrderCode,reworkOrderCode)
                .ne(ReworkOrderDetail::getStatus,status)
                .count();
    }

    @Override
    public List<ReworkOrderDetail> selectByReworkOrderCode(String reworkOrderCode) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(ReworkOrderDetail::getReworkOrderCode,reworkOrderCode)
                .list();
    }

    @Override
    public boolean deleteById(Integer id) {
        return mapper.deleteById(id) == 1;
    }
}
